<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>调色板</title>
    <style>
        .container{
            width: 400px;
            min-height: 300px;
            margin: 100px auto;
            border:solid 1px #ddd;
        }

        .container .show{
            width: 100%;
            height: 200px;
            background: #cae;
        }
        .form{
            padding: 10px;
        }
    </style>
</head>
<body>
    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{

            state = {
                r: 100,
                g: 0,
                b: 0,
                a: 1
            }

            render(){
                //解构赋值
                let {r,g,b,a} = this.state;
                return <div className="container">
                        <div className="show" style={{background: `rgba(${r},${g},${b},${a})`}}></div>
                        <div className="form">
                            R: <input type="range" min="0" max="255" value={r} onChange={this.change('r')} /><span>{r}</span><br />
                            G: <input type="range" min="0" max="255" value={g} onChange={this.change('g')} /><span>{g}</span><br />
                            B: <input type="range" min="0" max="255" value={b} onChange={this.change('b')} /><span>{b}</span><br />
                            A: <input type="range" min="0" step="0.02" max="1" value={a} onChange={this.change('a')} /><span>{a}</span><br />
                        </div>
                    </div>
            }

            change = (t) => {
                return (e) => {
                    this.setState({
                        [t] : e.target.value
                    })
                }
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));


    </script>
</body>
</html>